package org.jeecg.modules.fund.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.front.util.FundDate;
import org.jeecg.modules.fund.entity.DayCount;
import org.jeecg.modules.fund.entity.UserhomeFund;
import org.jeecg.modules.fund.mapper.DayCountMapper;
import org.jeecg.modules.fund.service.IDayCountService;
import org.jeecg.modules.fund.service.IUserhomeFundService;
import org.jeecg.modules.gongqiang.entity.Userhome;
import org.jeecg.modules.gongqiang.mapper.UserhomeMapper;
import org.jeecg.modules.gongqiang.service.IUserhomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Description: 平台基金统计表
 * @Author: jeecg-boot
 * @Date:   2024-09-30
 * @Version: V1.0
 */
@Service
public class DayCountServiceImpl extends ServiceImpl<DayCountMapper, DayCount> implements IDayCountService {
    @Autowired
    private IUserhomeService userhomeService;

    @Autowired
    private IUserhomeFundService userhomeFundService;

    @Override
    public DayCount totayCountStatic()
    {
        DayCount dayCount=new DayCount();
        dayCount.setCountTime(new Date());
        //今天基金余额
        QueryWrapper<Userhome> queryWrapper1=new QueryWrapper<>();
        queryWrapper1.select("SUM(fund_money) as fundMoney"); // 指定要求和的字段
        List<Object> results1 = userhomeService.listObjs(queryWrapper1); // 执行查询
        if(!results1.isEmpty()) {
            dayCount.setBalanceFund((Double) (results1.get(0)));
        }
        else
        {
            dayCount.setBalanceFund(0.00);
        }

        //今天基金累积购买金额
        QueryWrapper<UserhomeFund> queryWrapper2=new QueryWrapper<>();
        queryWrapper2.select("SUM(num) as num"); // 指定要求和的字段
        List<Object> results2 = userhomeFundService.listObjs(queryWrapper2); // 执行查询
        if(!results2.isEmpty()) {
            dayCount.setTotalFund((Double) (results2.get(0)));
        }
        else
        {
            dayCount.setTotalFund(0.00);
        }

        //今天基金购买金额
        Date totayStartTime= FundDate.getTodayStartTime();
        QueryWrapper<UserhomeFund> queryWrapper3=new QueryWrapper<>();
        queryWrapper3.ge("create_time",totayStartTime);
        queryWrapper3.select("SUM(num) as num"); // 指定要求和的字段
        List<Object> results3 = userhomeFundService.listObjs(queryWrapper3); // 执行查询
        if(!results3.isEmpty()) {
            dayCount.setTodayFund((Double) (results3.get(0)));
        }
        else
        {
            dayCount.setTodayFund(0.00);
        }
        return dayCount;

    }
}
